<?php
namespace app\wxapp\controller;

use app\common\entity\Result;
use app\Request;
use app\wxapp\service\UserSignService;
use app\wxapp\service\WechatUserService;
use think\facade\Db;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/9/29 0029
 * Time: 8:54
 */
class WechatUser extends Base {

    public function update(Request $request){
        $data = $request->post();
        $service = new WechatUserService();
        $model = $service->update($data,$this->user['id']);
        return Result::success($model);
    }

    public function updatePhone(Request $request){
        $data = $request->post();
        $service = new WechatUserService();
        $user = $service->updatePhone($data,$this->user['id']);
        return Result::success($user);
    }

    /**
     * 获取不在用户表的个人数据
     */
    public function getExtra(){
        $userSignService = new UserSignService();
        $data = [
            'isSign'=>$userSignService->isSignToday($this->user['id']),
            'signCountTotal'=>$userSignService->signCountTotal($this->user['id']),
            'signCountMonth'=>$userSignService->signCountMonth($this->user['id']),
        ];
        return Result::success($data);
    }

    /**
     * 签到
     */
    public function sign(){
        $service = new UserSignService();
        $service->sign($this->user['id']);
        return Result::success("签到成功");
    }

    /**
     *
     */
    public function remindStudy(){
        $service = new WechatUserService();
        $model = $service->remindStudy($this->user['id']);
        return Result::success($model);
    }



    public function getUserInfo(){
        $user = Db::table('wechat_user')->where(['id'=>$this->user['id']])->find();
        return Result::success($user);
    }
}